package main

import (
	"github.com/astaxie/beego"
	"softwareEngineering/controllers"
	_ "softwareEngineering/models"
	_ "softwareEngineering/routers"
	"strconv"
)

func main() {
	beego.InsertFilter("/admin", beego.BeforeRouter, controllers.FilterUser, true, false)
	beego.AddFuncMap("formatVideoTime", formatVideoTime)
	beego.Run()
}

func formatVideoTime(time int) string {
	h := time / 3600
	strH := ""
	m := (time - h*3600) / 60
	strM := ""
	s := time - h*3600 - m*60
	strS := ""
	if h < 10 {
		hh := strconv.Itoa(h)
		strH = "0" + hh
	} else {
		strH = strconv.Itoa(h)
	}

	if m < 10 {
		hh := strconv.Itoa(m)
		strM = "0" + hh
	} else {
		strM = strconv.Itoa(m)
	}
	if s < 10 {
		hh := strconv.Itoa(s)
		strS = "0" + hh
	} else {
		strS = strconv.Itoa(s)
	}

	if strH == "00" {
		return strM + ":" + strS

	} else {
		return strH + ":" + strM + ":" + strS
	}

}
